{include file="public/toper" /}
<script type="text/javascript" src="/static/js/myajax.js"></script>
<div class="x-nav">
    <span class="layui-breadcrumb">
        <a href="">规格管理</a>
        <a href="">商品类型</a>
    </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">&#xe666;</i></a>
</div>
<div class="x-body">
    <xblock class="demoTable">
        <button class="layui-btn" onclick="x_admin_show('添加类型','{:url(\'Type/add\')}','500','200')"><i class="layui-icon"></i>添加</button>
    </xblock>
    <table class="layui-hide" id="test" lay-filter="test"></table>
</div>
<style>
    .layui-table img {height: 37px;}
    .yes {color: #1BBC9D;cursor: default;}
    .no {color: #9ea3a7;cursor: default;}
</style>
<script type="text/html" id="action">
    <button class="layui-btn layui-btn layui-btn-xs"  onclick="x_admin_show('编辑','{:url(\'Type/add\')}?id={{d.type_id}}','500','200')"><i class="layui-icon">&#xe642;</i>编辑</button>
    <button class="layui-btn-danger layui-btn layui-btn-xs del_btn" id="{{d.type_id}}" lay-event="del"><i class="layui-icon">&#xe640;</i>删除</button>
</script>
<script>
    layui.use(['table','layer'], function(){
        var table = layui.table, $ = layui.jquery;
        var loading = layer.load(1, {shade: [0.1,'#fff'] });
        var tableIn = table.render({
            method: 'post',
            elem: '#test'
            ,url: "{:url('Type/index')}"
            ,id:'test'
            ,cols: [[
                {field:'type_id', width:80, title: '序号',fixed: true,align: 'center',type:'numbers'}
                ,{field:'name', width:150, title: '名称',align: 'center'}
                ,{width: 190,title: '操作', align: 'center', toolbar: '#action'}
            ]]
            ,page: false
            ,limit: 30
            ,limits:[30,60,90,120,150,180,210,240,270,300]
        });
        layer.close(loading);
        //搜索
        $('#search').on('click', function () {
            var key = $('#key').val();
            tableIn.reload({
                where: {key: key}
            });
        });


        //删除
        table.on('tool(test)', function(obj) {
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('您确定要删除【'+data.name+'】吗？',{btnAlign: 'c'}, function(index){
                    var loading = layer.load(1, {shade: [0.1,'#fff'] });
                    $.post("{:url('Type/del')}",{type_id:data.type_id},function(res){
                        layer.close(loading);
                        if(res.code==200){
                            layer.msg(res.msg,{time:1000,icon:1});
                            tableIn.reload();
                        }else{
                            layer.msg(res.msg,{time:1000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }
        });

    });

    //批量删除
    function delAll (argument) {
        var data = tableCheck.getData();
        var str = new Array();
        if(data.length>0){
            for(var i=0;i<data.length;i++){
                str[i] = data[i];
            }

            layer.confirm('您确定要删除改这'+data.length+'条数据?',{btnAlign: 'c'}, function(index){
                var loading = layer.load(0, {shade: false});
                $.post("{:url('Type/delete')}",{type_id:str},function(res){
                    layer.close(loading);
                    if(res.code==200){
                        layer.msg(res.msg, { time: 1000,icon: 1}, function(){
                            location.reload();//do something
                        });
                    }else{
                        layer.msg(res.msg,{time:1000,icon:2});
                    }
                });
                layer.close(index);
            });

        }else{
            layer.msg("请选择要删除的数据",{time:1000,icon:2});
        }
    }
</script>
{include file="public/footer"/}